package com.qianji.petmall.product.app;

import com.qianji.common.utils.PageUtils;
import com.qianji.common.utils.R;
import com.qianji.petmall.product.service.AttrService;
import com.qianji.petmall.product.vo.AttrRespVo;
import com.qianji.petmall.product.vo.AttrVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;



/**
 * 商品属性
 *
 * @author xiaoxin
 * @email 485350978@qq.com
 * @date 2022-01-07 14:35:43
 */
@RestController
@RequestMapping("product/attr")
public class AttrController {
    @Autowired
    private AttrService attrService;

    @GetMapping("{catIdPath}/list/{carId}")
    public R saveList(@RequestParam Map<String, Object> params,@PathVariable("carId") Long carId,
                      @PathVariable("catIdPath")String type){
        PageUtils page = attrService.queryAllList(params,carId,type);
        System.out.println("sdfsdf"+page);
        return R.ok().put("page",page);
    }
//    @GetMapping("/sale/list/{catelogId}")
//    public R saleList(@RequestParam Map<String, Object> params,@PathVariable("catelogId") Long carId){
//        PageUtils page = attrService.queryAllList(params,carId);
//        return R.ok().put("page",page);
//    }
    /**
     * 列表/product/attr/sale/list/{catelogId}
     */
    @RequestMapping("/list")
    //@RequiresPermissions("product:attr:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = attrService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{attrId}")
    //@RequiresPermissions("product:attr:info")
    public R info(@PathVariable("attrId") Long attrId){
//		AttrEntity attr = attrService.getById(attrId);
        AttrRespVo attr = attrService.selectPath(attrId);
        return R.ok().put("attr", attr);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("product:attr:save")
    public R save(@RequestBody AttrVo attr){
		attrService.saveAttr(attr);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:attr:update")
    public R update(@RequestBody AttrVo attr){
		attrService.updateAttr(attr);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:attr:delete")
    public R delete(@RequestBody Long[] attrIds){
		attrService.removeByIds(Arrays.asList(attrIds));

        return R.ok();
    }

}
